<?php
//Nguyen Van Binh
//suongmumc@gmail.com

defined( '_VALID_NVB' ) or die( 'Direct Access to this location is not allowed.' );
$tpl = new TemplatePower("template/header.htm");
$tpl->prepare();
$tpl->assignGlobal("site_address",$site_address);
if($_GET['title']){
	$tpl->assignGlobal("site_name",compile_title($_GET['title']).' - '.$CONFIG['site_name']);
}else{
	$tpl->assignGlobal("site_name",$CONFIG['site_name']);
}
$tpl->assignGlobal("site_keywords",$CONFIG['site_keywords']);
$tpl->assignGlobal("site_description",$CONFIG['site_description']);

$idmenu=intval($_GET['idmenu']);
include("modules/functionmenu.php");
include("modules/functionlink.php");


$tpl->assignGlobal("lang_dir",$lang_dir);

// tab menu bar
$sql="SELECT * FROM menu".$lang." WHERE active=1  ORDER BY thu_tu ASC, name ASC";
$db=$DB->query($sql);
$i=0;
while($rs=mysql_fetch_array($db)){
	if(in_array('menubar',setvitri($rs['id_menu']))){
		$tpl->newBlock("menubar");
		$i++;
		$tpl->assign("name",$rs['name']);	
		if(Get_Main_Id_Menu($idmenu)==$rs['id_menu']){
			$tpl->assign("clactive","active")	;
		}
		$tpl->assign("link",$site_address.$lang_dir.$rs['link_write']);
		$sql1="SELECT * FROM menu".$lang." WHERE active=1 AND parentid=$rs[id_menu] ORDER BY thu_tu ASC, name ASC";
		$db1=$DB->query($sql1);
		if(mysql_num_rows($db1)>0){
			$tpl->assign("arrow",'class="down"');
			$tpl->newBlock("showsubbar");
			while($rs1=mysql_fetch_array($db1)){
				$tpl->newBlock("submenubar");
				$tpl->assign("subname",$rs1['name']);
				$tpl->assign("link1",$site_address.$lang_dir.$rs1['link_write']);
				$sql2="SELECT * FROM menu".$lang." WHERE active=1 AND parentid=$rs1[id_menu] ORDER BY thu_tu ASC, name ASC";
				$db2=$DB->query($sql2);
				if(mysql_num_rows($db2)>0){
					$tpl->assign("arowsub1",'class="fly"');
					$tpl->newBlock("showsubbar2");
					while($rs2=mysql_fetch_array($db2)){
						$tpl->newBlock("submenubar2");
						$tpl->assign("subname2",$rs2['name']);
						$tpl->assign("link2",$site_address.$lang_dir.$rs2['link_write']);
						$sql3="SELECT * FROM menu".$lang." WHERE active=1 AND parentid=$rs2[id_menu] ORDER BY thu_tu ASC, name ASC";
						$db3=$DB->query($sql3);
						if(mysql_num_rows($db3)>0){
							$tpl->assign("arowsub2",'class="fly"');
							$tpl->newBlock("showsubbar3");
							while($rs3=mysql_fetch_array($db3)){
								$tpl->newBlock("submenubar3");
								$tpl->assign("subname3",$rs3['name']);
								$tpl->assign("link3",$site_address.$lang_dir.process_link($rs3['link'],$rs3['id_menu']));
							}
						}
					}
				}
			}
			
		}
	}
}


$sql="SELECT * FROM catlg WHERE postion='flashbanner'";
	$db=$DB->query($sql);
	if($rs=mysql_fetch_array($db)){
		$sql1="SELECT * FROM logo WHERE active=1 AND id_catlg=$rs[id_catlg] ORDER BY thu_tu DESC, name ASC";
		$db1=$DB->query($sql1);
		if($rs1=mysql_fetch_array($db1)){
			$tpl->newBlock("flashpage");
			if (get_file_extension($rs1['image'])=='swf' || get_file_extension($rs1['image'])=='SWF'){
				$tpl->assign("flash_page",embed_flash($site_address.$CONFIG['upload_image_path'].$rs1['image'],1000,247));	
			}else{
				$tpl->assign("flash_page","<img width='1000' src='".$site_address.$CONFIG['upload_image_path'].$rs1['image']."' border='0' >");
			}
		}		
	}	

// 
// menu left
$sql="SELECT * FROM menu".$lang." WHERE active=1  ORDER BY thu_tu ASC, name ASC";
$db=$DB->query($sql);
while($rs=mysql_fetch_array($db)){
	if(in_array('menuleft',setvitri($rs['id_menu']))){
		$tpl->newBlock("menuleft");		
		$tpl->assign("name",$rs['name']);	
		$tpl->assign("link",$site_address.$rs['link_write']);

		$sql1="SELECT * FROM menu".$lang." WHERE active=1 AND parentid=$rs[id_menu]  ORDER BY thu_tu ASC, name ASC";
		$db1=$DB->query($sql1);
		while($rs1=mysql_fetch_array($db1)){
			$tpl->newBlock("menuleft1");		
			$tpl->assign("name1",$rs1['name']);	
			$tpl->assign("link1",$site_address.$rs1['link_write']);
			//if($idmenu==$rs1['id_menu']){
				if($_GET['page']=='products'){
					$sql2="SELECT * FROM menu".$lang." WHERE active=1 AND parentid=$rs1[id_menu]  ORDER BY thu_tu ASC, name ASC";
					$db2=$DB->query($sql2);
					while($rs2=mysql_fetch_array($db2)){
						$tpl->newBlock("menuleft2");		
						$tpl->assign("name2",$rs2['name']);	
						$tpl->assign("link2",$site_address.$rs2['link_write']);
					}
				}
		//	}
		}		
	}
}



// support online

	$sql="SELECT * FROM yahoo WHERE active=1  ORDER BY thu_tu DESC, name ASC";
	$db=$DB->query($sql);
	while($rs=mysql_fetch_array($db)){
		$tpl->newBlock("yahoo")	;
		$tpl->assign("name",$rs['name']);		
		$tpl->assign("nic",$rs['nic']);
	}
$sql="SELECT * FROM static WHERE active=1 AND inwhere='hotline' ORDER BY thu_tu DESC, id_static DESC LIMIT 0,1";
$db=$DB->query($sql);
if($rs=mysql_fetch_array($db)){
	$tpl->assignGlobal("hotline",$rs['content'])	;
}

// quang cao trai
$sql="SELECT * FROM catlg WHERE active=1 AND postion='advleft' ORDER BY thu_tu DESC, name ASC";
$db=$DB->query($sql);
while($rs=mysql_fetch_array($db)){
	$sql1="SELECT * FROM logo WHERE active=1 AND id_catlg=$rs[id_catlg] ORDER BY thu_tu DESC, name ASC";
	$db1=$DB->query($sql1);
	while($rs1=mysql_fetch_array($db1)){
		
		if($rs1['image']){
			$tpl->newBlock("advitem");
			if (get_file_extension($rs1['image'])=='swf' || get_file_extension($rs1['image'])=='SWF'){
				$tpl->assign("adv",embed_flash($site_address.$CONFIG['upload_image_path'].$rs1['image'],1000,127));	
			}else{
				$tpl->assign("adv","<img width='226' src='".$site_address.$CONFIG['upload_image_path'].$rs1['image']."' border='0' >");
			}
			$tpl->assign("link",$rs1['link']);
			$tpl->assign("target",$rs1['target']);
		}
		
	}
		
}
//weblink
$sql="SELECT * FROM catlg WHERE active=1 AND postion='weblink' ORDER BY thu_tu DESC, name ASC";
$db=$DB->query($sql);
while($rs=mysql_fetch_array($db)){
	$sql1="SELECT * FROM logo WHERE active=1 AND id_catlg=$rs[id_catlg] ORDER BY thu_tu DESC, name ASC";
	$db1=$DB->query($sql1);
	while($rs1=mysql_fetch_array($db1)){
		
		if($rs1['image']){
			$tpl->newBlock("weblink");
			$tpl->assign("name",$rs1['name']);
			$tpl->assign("link",$rs1['link']);
			$tpl->assign("target",$rs1['target']);
		}
		
	}
		
}

$tpl->printToScreen();



?>